package com.achievo.reportserver.config;

import java.io.File;
import java.io.IOException;

import org.apache.commons.digester.Digester;
import org.xml.sax.SAXException;


/**
 * 
 * Report Server
 * write at Jan 21, 2010
 * @author <a href="mailto:chinaoryx@gmail.com">Hyman.Zhang (Zhang Haipeng)</a>
 * @version 1.0
 * 
 *
 */
public class ConfigUtils {
	
	
	public ReportRoot parseConfigFile(File configFile) throws IOException, SAXException{
		ReportRoot root = null;
		Digester digester = new Digester();

		digester.setValidating(false);
		digester.addObjectCreate("reportList", ReportRoot.class);
		digester.addObjectCreate("reportList/report", ReportDef.class);
		digester.addSetNext("reportList/report", "addReport" );
		
		digester.addObjectCreate("reportList/report/params/param", ReportParam.class);
		digester.addSetNext("reportList/report/params/param", "addParam" );
		
		digester.addCallMethod("reportList/report/params/param/paramName", "setParamName", 0);
		digester.addCallMethod("reportList/report/params/param/paramLabel", "setParamLabel", 0);
		digester.addCallMethod("reportList/report/params/param/paramType", "setParamType", 0);
		
		
		
		digester.addSetProperties("reportList/report", "reportId", "reportId");
		digester.addSetProperties("reportList/report", "groupId", "groupId");
		
		
		digester.addCallMethod("reportList/report/reportTemplateFile", "setReportTemplateFile", 0);
		digester.addCallMethod("reportList/report/reportEngine", "setReportEngine", 0);
		digester.addCallMethod("reportList/report/datasource", "setDatasource", 0);
		digester.addCallMethod("reportList/report/reportType", "setReportType", 0);
		digester.addCallMethod("reportList/report/isSync", "setIsSync", 0);
//		digester.addCallMethod("reportList/report/expireTime", "setExpireTime", 0, new Class[]{Long.class});
//		digester.addcallme
		
		
		Object obj = digester.parse(configFile);
		root = (ReportRoot) obj;		
		return root;
	}

}
